/*
* Copyright (c) 2009, Roc King
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
*     * Redistributions of source code must retain the above copyright
*       notice, this list of conditions and the following disclaimer.
*     * Redistributions in binary form must reproduce the above copyright
*       notice, this list of conditions and the following disclaimer in the
*       documentation and/or other materials provided with the distribution.
*     * Neither the name of the OwnWaterloo,Roc King nor the
*       names of its contributors may be used to endorse or promote products
*       derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include <stdio.h>
#include <stdlib.h>

#include "retrieve.h"

int CC_STDCALL print_all(node* n) {
    printf("%d ",n->value);
    return continue_enumerate;
}

int CC_STDCALL find_if_eqauls_to_1212(node* n) {
    if (n->value == 1212 )
        return terminate_enumerate;
    return continue_enumerate;
}

/*
int CC_STDCALL find_if_eqauls_to_326(node* n) {
    return n->value==326?terminate_enumerate:continue_enumerate
}
int CC_STDCALL find_if_eqauls_to_m(node* n) {
    return n->value==m?terminate_enumerate:continue_enumerate
}
*/


int CC_STDCALL fill_zero(node* n) {
    n->value = 0;
    return continue_enumerate;
}

/*
int CC_STDCALL fill_one(node* n) { n->value = 1; return continue_enumerate; }
int CC_STDCALL fill_m(node* n) { n->value = m; return continue_enumerate; }
*/


int main() {

    node array_list[] = { {86},{1212},{326},{326},{1212},{86}, };
    node* const last = array_list + sizeof(array_list)/sizeof(array_list[0]);
    node* p = 0;

    printf("the values of this array list are : ");
    p = retrieve_array_list(array_list,last,print_all);
    printf("\n");

    printf("\nfinding the node whose value equals to 1212\n");
    for (p = array_list
        ;p = retrieve_array_list(p,last,find_if_eqauls_to_1212)
        ,p != last
        ;++p )
    {
        printf("index=%d ",p - array_list);
    }
    printf("\n\n");

    printf("fill all the nodes of this array list with zero\n");
    retrieve_array_list(array_list,last,fill_zero);
    printf("now, the values of this array list are :");
    retrieve_array_list(array_list,last,print_all);
    printf("\n");

    printf("\npress enter to exit\n");
    (void)getchar();
    return 0;
}
